package com.wholesale.beans;

import org.json.JSONException;
import org.json.JSONObject;

public class WhoAttribute {

	private int attrId ;
	private int catId ;
	private String attrName ;
	private String attrInputType ;
	private String attrType ;
	private String attrValues ;
	private String attrIndex ;
	private String sortOrder ;
	private Boolean isLinked ;
	private String attrGroup ;
	private JSONObject jsonObject;
	public int getAttrId() {
		
		return attrId;
	}
	public void setAttrId(int attrId) {
		this.attrId = attrId;
	}
	public int getCatId() {
		
		return catId;
	}
	public void setCatId(int catId) {
		this.catId = catId;
	}
	public String getAttrName() {
		
		return attrName;
	}
	public void setAttrName(String attrName) {
		this.attrName = attrName;
	}
	public String getAttrInputType() {
		
		return attrInputType;
	}
	public void setAttrInputType(String attrInputType) {
		this.attrInputType = attrInputType;
	}
	public String getAttrType() {
		
		return attrType;
	}
	public void setAttrType(String attrType) {
		this.attrType = attrType;
	}
	public String getAttrValues() {
		
		return attrValues;
	}
	public void setAttrValues(String attrValues) {
		this.attrValues = attrValues;
	}
	public String getAttrIndex() {
		
		return attrIndex;
	}
	public void setAttrIndex(String attrIndex) {
		this.attrIndex = attrIndex;
	}
	public String getSortOrder() {
		
		return sortOrder;
	}
	public void setSortOrder(String sortOrder) {
		this.sortOrder = sortOrder;
	}
	public boolean isLinked() {
		
		return isLinked;
	}
	public void setLinked(boolean isLinked) {
		this.isLinked = isLinked;
	}
	public String getAttrGroup() {
		
		return attrGroup;
	}
	public void setAttrGroup(String attrGroup) {
		this.attrGroup = attrGroup;
	}
	
	public String toJsonString(){
		JSONObject loginObject = new JSONObject();
		try {
			loginObject.put("attrId", attrId);
			loginObject.put("catId", catId);
			loginObject.put("attrName", attrName);
			loginObject.put("attrInputType", attrInputType);
			loginObject.put("attrType", attrType);
			loginObject.put("attrValues", attrValues);
			loginObject.put("attrIndex", attrIndex);
			loginObject.put("sortOrder", sortOrder);
			if(isLinked){
				loginObject.put("isLinked", 1);
			}else{
				loginObject.put("isLinked", 0);
			}
			loginObject.put("attrGroup", attrGroup);
		} catch (Exception e) {
		}
		return loginObject.toString();
	}
	
	public void jsonAnalytic(String jsonString){
		
		try {
			jsonObject = new JSONObject(jsonString);
			jsonAnalytic(jsonObject);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void jsonAnalytic(JSONObject jsonObject){
		this.jsonObject = jsonObject;
		
			try {
				attrId = jsonObject.getInt("attrId");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				catId = jsonObject.getInt("catId");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				attrName = jsonObject.getString("attrName");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				attrInputType = jsonObject.getString("attrInputType");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				attrType = jsonObject.getString("attrType");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				attrValues = jsonObject.getString("attrValues");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				attrIndex = jsonObject.getString("attrIndex");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				sortOrder = jsonObject.getString("sortOrder");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				if(jsonObject.getString("isLinked").equals("1")){
					isLinked = true ;
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
			try {
				attrGroup = jsonObject.getString("attrGroup");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		
	}
	
}
